import axios from '@/libs/axios1'
import { escape2Html } from '@/libs/utils'
let jsonHeaders = {
	'content-type': 'application/json;charset=UTF-8'
}
let tool = '/tool-manage'
let contentNetns = '/scientific/contentNetns';
//获取工具库列表
export const getToolManageList = (name,params) => {
	return axios({
		url: `${tool}/tool/page/${name}`,
		method: 'get',
		params,
		headers: jsonHeaders
	})
}

//创建或修改工具库
export const addOrUpdateToolManage = (data) => {
	return axios({
		url: `${tool}/tool`,
		method: 'post',
		data,
		headers: jsonHeaders
	})
}

//删除工具库
export const deleteToolManage = (id) => {
	return axios({
		url: `${tool}/tool/${id}`,
		method: 'delete',
		headers: jsonHeaders
	})
}

//同步工具
export const syncTool = (id,typeName) => {
	return axios({
		url: `${tool}/tool/copy/${id}/${typeName}`,
		method: 'post',
		headers: jsonHeaders
	})
}

//批量同步
export const batchSyncTool = ids => {
	return axios({
		url: `${tool}/tool/copy`,
		method: 'post',
		data:ids,
		headers: jsonHeaders
	})
}

//获取当前用户工具库系统账号
export const getToolAccount = () => {
	return axios({
		url: `${tool}/users/info`,
		method: 'get',
		headers: jsonHeaders
	})
}
//重置账号密码
export const resetPassword = (data) => {
	return axios({
		url: `${tool}/users/info`,
		method: 'post',
		data,
		headers: jsonHeaders
	})
}

//失败重新生成工具库账号
export const resetToolAccount = () => {
	return axios({
		url: `${tool}/users/rest`,
		method: 'post',
		headers: jsonHeaders
	})
}


//工具库单个分享
export const toolShare = (data) => {
	return axios({
		url: `${tool}/share`,
		method: 'post',
		data,
		headers: jsonHeaders
	})
}

//工具库批量分享
export const toolShares = (data) => {
	return axios({
		url: `${tool}/share/batch`,
		method: 'post',
		data,
		headers: jsonHeaders
	})
}

//工具库取消分享
export const cancelShare = (id) => {
	return axios({
		url: `${tool}/share/${id}`,
		method: 'put',
		headers: jsonHeaders
	})
}

//工具库分享列表
export const shareList = (toolId,params) => {
	return axios({
		url: `${tool}/share/page/${toolId}`,
		method: 'get',
		params,
		headers: jsonHeaders
	})
}

// 工具测试项目列表
export const testProjectList = (toolId,params) => {
	return axios({
		url: `${tool}/tool/scene/${toolId}/page`,
		method: 'get',
		params,
		headers: jsonHeaders
	})
}

//启用工具库通道
export const startToolTunnel= (projectId,subnetId) => {
    return axios({
        // url: `${contentNetns}/${projectId}/tool/${subnetId}`,
        url: `${contentNetns}/new/${projectId}/tool/${subnetId}`,
        method: 'POST',
        headers: jsonHeaders,
    });
};

//关闭工具库通道
export const stopToolTunnel= (projectId,subnetId) => {
    return axios({
        // url: `${contentNetns}/${projectId}/tool/${subnetId}/stop`,
        url: `${contentNetns}/new/${projectId}/tool/${subnetId}/stop`,
        method: 'POST',
        headers: jsonHeaders,
    });
};

//查看工具库通道详情
export const getToolTunnelDetail = (projectId,subnetId) => {
    return axios({
        // url: `${contentNetns}/${projectId}/tool/${subnetId}/detail`,
        url: `${contentNetns}/new/${projectId}/tool/${subnetId}/detail`,
        method: 'GET',
        headers: jsonHeaders,
    });
};
